function PolygonRenderer(map, cIcon, name) {
	PolygonRenderer.baseConstructor.call(this, map, cIcon, name);
	this.fillColor = cIcon.color;
	this.lineColor = cIcon.lineColor;
	this.dPoints = new Array();	
	this.polygon = null;
	this.addPointToPoly();
};
C_UTIL.extend(PolygonRenderer,Renderer);
PolygonRenderer.prototype.closePoly = function() {
		var firstPoint = this.dPoints[0];
		this.marker.setPoint(firstPoint);
		this.addPointToPoly();		
		this.drawPolygon();
		this.deactivate();			
				
		/*
		var marker = new GMarker(firstPoint, {draggable:false});
		this.map.addOverlay(marker);
		this.map.panTo(marker.getPoint());
		GEvent.addDomListener(marker, "click", function(){
			marker.openInfoWindowHtml("<p>how do you like your polygon?</p>");
		});
		*/
		
};
PolygonRenderer.prototype.getCloseShapeHandler = function(instance) {
	return function(){
		instance.closePoly();
	};
};
PolygonRenderer.prototype.deactivate = function() {
	if (this.active) {
		PolygonRenderer.superClass.deactivate.call(this)
		try {GEvent.removeListener(this.handles.closeshape);}catch(e){}
	}
};
PolygonRenderer.prototype.getIconUrl = function() {
	var img;
	if (this.dPoints && this.dPoints.length>1) {
		img = this.marker.getIcon().image;
	} else {
		img = 'js/map/annotate/icons/colour045.png';	
	}
	return img;
};
PolygonRenderer.prototype.activate = function() {
	PolygonRenderer.superClass.activate.call(this);
	GEvent.bind(this.marker, "dragend", this, this.dragEnd);
	GEvent.bind(this.marker, "drag", this, this.dragMarker);

	this.handles.closeshape = GEvent.addListener(this.map,"closeshape",this.getCloseShapeHandler(this));
};
PolygonRenderer.prototype.drawPolygon = function() {
	if (this.polygon) {
		this.map.removeOverlay(this.polygon);
	}
	if (this.dPoints.length>1) {
		if (this.fillColor) {
			this.polygon = new GPolygon(this.dPoints, this.lineColor, 1,1,this.fillColor);	
		} else {
			this.polygon = new GPolyline(this.dPoints, this.lineColor);		
		}
		var pl = this.polygon;
		this.map.addOverlay(pl);		
	}
};
PolygonRenderer.prototype.dragEnd = function() {
	if (this.dPoints.length==1)
	{
		this.addPointToPoly();
	}
};
PolygonRenderer.prototype.dragMarker = function() {
	this.dPoints.splice((this.dPoints.length-1),1,this.marker.getPoint());
	this.drawPolygon();
};
PolygonRenderer.prototype.dragStart = function() {
	PolygonRenderer.superClass.dragStart.call(this);

	if (this.dPoints.length>1)
	{
		this.addPointToPoly();
	}
};
PolygonRenderer.prototype.addPointToPoly = function() {
	this.dPoints.push(this.marker.getPoint());
	this.setIcon();
};

					
					
PolygonRenderer.prototype.setMarker = function(point) {
	if (point) {
		this.marker.setPoint(point);
		if (this.dPoints.indexOf(point)==-1) {
			this.addPointToPoly();
		}
	} 
	this.drawPolygon();
	if (this.dPoints.length==1) {
		this.setIcon();
	}
};

PolygonRenderer.prototype.removeLastPoint = function() {
	this.dPoints.splice((this.dPoints.length-1),1);
	
	this.map.getInfoWindow().hide();
	this.setMarker(this.dPoints[(this.dPoints.length-1)]);
};	
PolygonRenderer.prototype.removeAllPoints = function() {
	this.deactivate();

	this.map.removeOverlay(this.polygon);
	this.map.removeOverlay(this.marker);
	this.prototype = null;
	this.fillColor = null;
	this.lineColor = null;
	this.icon = null;
	this.marker =null;
	this.name = null;
	this.dPoints = null;	
	this.polygon = null;
	this.handles = null;
	this.imageUrl = null;
	this.map = null;
};					